
package com.trydofor.id.core;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.annotation.Nullable;

import com.trydofor.aloe.exception.FakeException;

/**
 * A Maker.
 * 
 * @param <T> the TYPE to make.
 * @author : Shi Rongjiu (www.trydofor.com)
 * @since 0.9
 */
public interface A9Maker<T> {
    
    /**
     * make a TYPE, waiting if necessary until completed.
     * 
     * @return @Nullable TYPE, {@code null} if nothing to make
     * @throws FakeException if got an exception
     */
    @Nullable
    T make();
    
    /**
     * make a TYPE, waiting if necessary for at most the given time.
     * if the timeout is not positive or the unit is null, it acts as next();
     * 
     * @param timeout the maximum time to wait
     * @param unit @Nullable the time unit of the timeout argument
     * @return TYPE, {@code null} if nothing to make
     * @throws InterruptedException if the current thread was interrupted while waiting
     * @throws TimeoutException if the wait timed out
     * @throws FakeException if got a handled exception
     */
    @Nullable
    T make(long timeout, @Nullable TimeUnit unit) throws InterruptedException, TimeoutException;
}
